package com.eboy.readwritexml;

import java.io.InputStream;
import java.util.List;

import com.eboy.domain.Person;
import com.eboy.readwritexml.R;
import com.eboy.service.PersonService;

import android.R.id;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Button btn1 = null;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        btn1 = (Button)findViewById(R.id.button1);
        btn1.setOnClickListener(new Btn1Click());   
    }
    
    private final class Btn1Click implements View.OnClickListener {
    	public void onClick(View v) {
    		InputStream inputStream = getClass().getClassLoader().getResourceAsStream("person.xml");
    		List<Person> persons;
			try {
				persons = PersonService.getPersons(inputStream);
				for (Person person : persons){
	    			Toast.makeText(getApplicationContext(), person.toString(), Toast.LENGTH_SHORT).show();
	    		}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}    			
		}
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    
}
